package com.song.tools.songtest.convertor;

import com.song.tools.mvc.convertor.AggregationConvertor;
import com.song.tools.songtest.beans.bo.SysUserBo;
import com.song.tools.songtest.beans.poi.SysUserExportDto;
import com.song.tools.songtest.beans.poi.SysUserImportDto;
import com.song.tools.songtest.beans.query.SysUserQuery;
import com.song.tools.songtest.beans.request.SysUserQueryRequest;
import com.song.tools.songtest.beans.request.SysUserSaveRequest;
import com.song.tools.songtest.beans.request.SysUserUpdateRequest;
import com.song.tools.songtest.beans.response.SysUserQueryResponse;
import com.song.tools.songtest.beans.response.SysUserSaveResponse;
import com.song.tools.songtest.beans.response.SysUserUpdateResponse;
import com.song.tools.songtest.constants.SexEnum;
import com.song.tools.songtest.constants.StatusEnum;
import com.song.tools.songtest.dao.entity.SysUser;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 用户表 转换器
 * </p>
 *
 * @author song tools
 * @since 2024-07-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysUserConvertor implements AggregationConvertor<SysUser, SysUserBo, SysUserQuery, SysUserQueryRequest, SysUserQueryResponse,
        SysUserSaveRequest, SysUserSaveResponse, SysUserUpdateRequest, SysUserUpdateResponse, SysUserImportDto, SysUserExportDto> {

    @Override
    public abstract SysUser entityBoToEntity(SysUserBo sysUserBo);

    @Override
    public abstract SysUserBo entityToEntityBo(SysUser sysUser);

    @Override
    public abstract SysUserQueryResponse entityBoToQueryResponse(SysUserBo sysUserBo);

    @Override
    public abstract SysUserQuery queryRequestToQuery(SysUserQueryRequest queryRequest);

    @Override
    public abstract SysUserBo saveRequestToEntityBo(SysUserSaveRequest request);

    @Override
    public abstract SysUserSaveResponse entityBoToSaveResponse(SysUserBo sysUserBo);

    @Override
    public abstract SysUserBo updateRequestToEntityBo(SysUserUpdateRequest request);

    @Override
    public abstract SysUserUpdateResponse entityBoToUpdateResponse(SysUserBo sysUserBo);

    @Override
    public abstract List<SysUser> entityBoToEntity(List<SysUserBo> entityBo);

    @Override
    public abstract List<SysUserBo> entityToEntityBo(List<SysUser> entity);

    @Override
    public abstract SysUserExportDto entityBoToExportDto(SysUserBo entityBo);

    @Override
    public abstract SysUserBo importDtoToEntityBo(SysUserImportDto importDto);

    @Override
    public abstract List<SysUserBo> importDtoToEntityBo(List<SysUserImportDto> importDto);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysUser sysUser, SysUserBo sysUserBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysUserBo sysUserBo, SysUser sysUser) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysUserQuery sysUserQuery, SysUserQueryRequest sysUserQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysUserQueryResponse sysUserQueryResponse, SysUserBo sysUserBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    @AfterMapping
    public void afterMappingEntityBoToSaveResponse(@MappingTarget SysUserSaveResponse sysUserSaveResponse, SysUserBo sysUserBo) {
        // entityBoToSaveResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToSaveResponse()
    }

    @AfterMapping
    public void afterMappingSaveRequestToEntityBo(@MappingTarget SysUserBo sysUserBo, SysUserSaveRequest sysUserSaveRequest) {
        // saveRequestToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingSaveRequestToEntityBo()
    }

    @AfterMapping
    public void afterMappingEntityBoToUpdateResponse(@MappingTarget SysUserUpdateResponse sysUserUpdateResponse, SysUserBo sysUserBo) {
        // entityBoToUpdateResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToUpdateResponse()
    }

    @AfterMapping
    public void afterMappingUpdateRequestToEntityBo(@MappingTarget SysUserBo sysUserBo, SysUserUpdateRequest sysUserUpdateRequest) {
        // updateRequestToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingUpdateRequestToEntityBo()
    }

    @AfterMapping
    public void afterMappingImportDtoToEntityBo(@MappingTarget SysUserBo sysUserBo, SysUserImportDto sysUserImportDto) {
        // importDtoToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingImportDtoToEntityBo()
    }

    @AfterMapping
    public void afterMappingEntityBoToExportDto(@MappingTarget SysUserExportDto sysUserExportDto, SysUserBo sysUserBo) {
        // entityBoToExportDto() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToExportDto()
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }

    public Integer sexEnumToInteger(SexEnum sexEnum) {
        if (Objects.isNull(sexEnum)) {
            return null;
        }
        return sexEnum.getCode();
    }

    public SexEnum integerToSexEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return SexEnum.of(code);
    }
}
